<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>汽车之家</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <meta name="x5-fullscreen" content="true">
    <meta name="full-screen" content="yes">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <script type="text/javascript">
        document.documentElement.style.fontSize = window.innerWidth/3.75 + 'px'
    </script>
</head>
<body>

    <section class="bg3">
        <div id="qrcode">
        </div>
        <div class="hc_bg">
            <img id="header_img" src="" class="tx">
            <img id="min_car" src="" class="car_s">
            <p id="car_text">

            </p>
        </div>
        <div class="line_bg">
            <p>
                <span>
                    <em class="car_name"></em>
                </span>
            </p>
            <div class="carimg">
                <img id="big_car" src="">
            </div>
        </div>
        <div class="carshi">
            <img id="carshi" src="images/hbB.png">
        </div>

    </section>
    <div class="down">
        <img src="images/down.png" style="display:none">
    </div>
</body>
<script src="js/jquery.js"></script>
<script src="js/common.js"></script>
<script src="js/jquery.qrcode.js"></script>
<script src="js/html2canvas.min.js"></script>
<script src="car.js"></script>
<script>

    var car_num = Math.floor(Math.random()*50+1);

    var shi_num = Math.floor(Math.random()*6);


    function load (){
        var startY = '';     // 触摸开始时的纵坐标  
        var moveY = '';     // 触摸移动中的纵坐标  
        // var endY = '';     // 触摸结束的纵坐标  
  
        document.addEventListener('touchstart',touch, { passive: false });  
        document.addEventListener('touchmove',touch, { passive: false });  
        document.addEventListener('touchend',touch, { passive: false });  
          
        function touch (event) {  
            var event = event || window.event;
            var oInp = document.getElementById("inp");  
            switch(event.type){  
                case "touchstart":
                    startY = event.touches[0].clientY;  
                    break;  
                // case "touchend":  
                //  break;  
                case "touchmove":
                    event.preventDefault();
                    moveY = event.touches[0].clientY;  
                    if (startY - moveY > 20) {
                        window.location.href="pre_share.html"
                    }
                    break;  
            }  
        }  
    }

    name = localStorage.getItem('name');
    text = localStorage.getItem('text');
    var car_text;
    $("#header_img").attr('src', localStorage.getItem('header_img'))
    $("#min_car").attr('src', 'images/car_images/' +car_num+ '.png')
    $("#big_car").attr('src', 'images/car_images/'+car_num+ '.png')
    $(".car_name").text(car_array[car_num])
    switch (text) {
        case "1":car_text = '<span>“左手事业 右手家庭”</span><span>XXX昨日怒提新车</span>';break;
        case "2":car_text = '<span>“要全款，我不喜欢贷款”</span><span>太膨胀！XXX买车眼都不眨</span>';break;
        case "3":car_text = '<span>“买台车而已，别惊讶”</span><span>一高兴就买车，XXX真任性</span>';break;
    }

    $("#car_text").html(car_text.replace('XXX',name))

    $("#carshi").attr('src','images/car/shi'+ shi_num +'.png')


    $(function(){

                html2canvas(document.querySelector('section')).then(function(canvas) {
                    document.body.appendChild(canvas);
                    var url = canvas.toDataURL("image/jpeg");
                    console.log('upload')
                    localStorage.setItem('ret_url',url)
                    $.ajax({
                        type:'POST',
                        url:'/index/create',
                        data:{'img_url':localStorage.getItem('ret_url')},
                        success:function(data){
                            url = data.url
                            new QRCode(document.getElementById("qrcode"), url);
                            html2canvas(document.querySelector('section')).then(function(canvas) {
                                document.body.appendChild(canvas);
                                var url = canvas.toDataURL("image/jpeg");
                                localStorage.setItem('ret_url',url)
                                $("#qrcode img").hide()
                                console.log('can2')
                                $.ajax({
                                    type:'POST',
                                    url:'/index/create',
                                    data:{'img_url':localStorage.getItem('ret_url')},
                                    success:function(data){
                                        url = data.url
                                        localStorage.setItem('share_url',data.url)
                                        load();
                                        $('.down img').show()

                                    }
                                })


                            });

                        }
                    })

                });


    })
</script>
</html>